import 'package:flutter/material.dart';

class LogoAnimation2 extends StatefulWidget {
  const LogoAnimation2({super.key});

  @override
  State<LogoAnimation2> createState() => _LogoAnimation2State();
}

class _LogoAnimation2State extends State<LogoAnimation2>
    with SingleTickerProviderStateMixin {
  late Animation<double> _animation;
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();

    // IntTween
    // ColorTween

    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    );
    _animation = CurvedAnimation(curve: Curves.linear, parent: _controller)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          _controller.reverse();
        } else if (status == AnimationStatus.dismissed) {
          _controller.forward();
        }
      })
      ..addStatusListener((status) => print('$status'));
    _controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Center(child: AnimatedLogo(animation: _animation));
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}

class AnimatedLogo extends AnimatedWidget {
  AnimatedLogo({super.key, required Animation<double> animation})
    : super(listenable: animation);

  final _sizeTween = Tween<double>(begin: 0, end: 300);
  final _opacityTween = Tween<double>(begin: 0, end: 1);

  @override
  Widget build(BuildContext context) {
    final animation = listenable as Animation<double>;
    return Center(
      child: Opacity(
        opacity: _opacityTween.evaluate(animation),
        child: Container(
          margin: const EdgeInsets.symmetric(vertical: 10),
          height: _sizeTween.evaluate(animation),
          width:_sizeTween.evaluate(animation),
          child: const FlutterLogo(),
        ),
      ),
    );
  }
}
